import pymysql

def query_data():
    # 连接数据库
    con = pymysql.connect(host='localhost', user='root', password='root', database='test', port=3306, charset='utf8')
    # 创建游标
    cur = con.cursor()
    #编写sql语句
    sql = "select * from emp"
    # 执行sql语句
    cur.execute(sql)
    #获取查询结果
    result = cur.fetchall()
    print (result)
    #关闭游标
    cur.close()
    # 关闭连接
    con.close()

if __name__ == '__main__':
    query_data()